<?php
namespace Models\Model;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\Db\Sql\Predicate;
use Zend\Db\Sql\Expression;
class LevelCompletedTable
{
    protected $tableGateway;
	protected $select;
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
		$this->select = new Select();
    }
	
	public function saveLevelResults($levelResults)
    {
		$data = array(
			'user_id' 	  	       => $levelResults['user_id'],		
			'course_id' 		   => $levelResults['course_id'],  		
			'subject_id' 		   => $levelResults['subject_id'],		
			'level' 		       => $levelResults['level'],
			'status'  	           => 1				
		);	
		$insertresult=$this->tableGateway->insert($data);	
		return $this->tableGateway->lastInsertValue;		
    }	
	// update
	public function updateLevelResults($levelResults)
    {
		$data = array(
			'user_id' 	  	       => $levelResults['user_id'],		
			'course_id' 		   => $levelResults['course_id'],  		
			'subject_id' 		   => $levelResults['subject_id'],		
			'level' 		       => $levelResults['level'],
			'status'  	           => 1				
		);	
		 $updateuserid=$this->tableGateway->update($data, array('user_id' =>$levelResults['user_id']));
	   return $updateuserid; 	
    }
	
	public function checkUser($user_id){
		$select = $this->tableGateway->getSql()->select();
		$select->where('user_id="'.$user_id.'"');
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;
	}
	public function getUserLevel($user_id,$course_id,$subject_id){
		$select = $this->tableGateway->getSql()->select();
		$select->where('user_id="'.$user_id.'"');
		$select->where('subject_id="'.$course_id.'"');
		$select->where('course_id="'.$subject_id.'"');
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;
	}
}